﻿
<div ms-controller="tmpmodelview">
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            城市
        </label>
        <div class="controls">
            <select class="input-large input-xfat" ms-duplex="ModelData.Client">
                <option ms-repeat-el="ClientList" ms-attr-value="el.ID">{{el.CodeName}}</option>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            分类
        </label>
        <div class="controls">
            <select class="input-large input-xfat" ms-duplex="ModelData.Type1">
                <option ms-repeat-el="TypeData" ms-attr-value="el.ID">{{el.TypeName}}</option>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            商家名称：
        </label>
        <div class="controls">
            <input type="text" class="input-xxlarge input-xfat" placeholder="请输入标题" ms-duplex="ModelData.Title" >
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            商家描述：
        </label>
        <div class="controls">
            <input type="text" class="input-xxlarge input-xfat" placeholder="请输入描述" ms-duplex="ModelData.Desp">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            展示图：
        </label>
        <div class="controls" style="width:900px">
            <ul class="sui-row-fluid" id="layer-photos-demo">
                <li class="span2" ms-repeat-el="FileData">
                    <div class="img-round">
                        <img ms-attr-layer-src="{{ComFunJS.FilePath(el)}}" ms-attr-data-id="el" ms-attr-src="ComFunJS.FilePath(el,'/100/100')" alt="">
                    </div>
                    <label>
                        <label> <a href="javascript:void(0);" class="sui-btn btn-bordered btn-small btn-danger" ms-click="DelFile(el)">删除</a> </label>
                    </label>
                </li>
                <li class="span2">
                    <button ms-click="FileUpload()" style="margin:15px 0" class="sui-btn btn-xlarge btn-success">添加图片</button>
                </li>
            </ul>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            联系人：
        </label>
        <div class="controls">
            <input type="text" class="input-xxlarge input-xfat" placeholder="请输入联系人" ms-duplex="ModelData.Contact">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            联系电话：
        </label>
        <div class="controls">
            <input type="text" class="input-xxlarge input-xfat" placeholder="请输入联系电话" ms-duplex="ModelData.ContactTel">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            地址：
        </label>
        <div class="controls">
            <input type="text" class="input-xxlarge input-xfat" placeholder="请输入地址" ms-duplex="ModelData.Address">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            营业执照：
        </label>
        <div class="controls" style="width:900px">
            <ul class="sui-row-fluid" id="layer-photos-demo">
                <li class="span2" >
                    <div class="img-round">
                        <img ms-attr-layer-src="{{ComFunJS.FilePath(ModelData.License)}}" ms-attr-data-id="el" ms-attr-src="ComFunJS.FilePath(ModelData.License,'/100/100')" alt="">
                    </div>
                    <label>
                        <label> <a href="javascript:void(0);" class="sui-btn btn-bordered btn-small btn-danger" ms-click="DelFile2('',2)">删除</a> </label>
                    </label>
                </li>
                <li class="span2">
                    <button ms-click="FileUpload2(2)" style="margin:15px 0" class="sui-btn btn-xlarge btn-success">添加图片</button>
                </li>
            </ul>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            <b style="color: #f00;">*</b>
            简介：
        </label>
        <div class="controls">
            <textarea rows="10" class="input-xxlarge input-xfat" placeholder="请输入简介" ms-duplex="ModelData.Summary"></textarea>
            <!--<input type="text" class="input-xlarge input-xfat" placeholder="请输入简介" ms-duplex="ModelData.Summary">-->
        </div>
    </div>
    <div class="control-group">
        <label class="control-label v-top">
            产品图片：
        </label>
        <div class="controls" style="width:900px">
            <ul class="sui-row-fluid" id="layer-photos-demo">
                <li class="span2" ms-repeat-el="FileData2">
                    <div class="img-round">
                        <img ms-attr-layer-src="{{ComFunJS.FilePath(el)}}" ms-attr-data-id="el" ms-attr-src="ComFunJS.FilePath(el,'/100/100')" alt="">
                    </div>
                    <label>
                        <label> <a href="javascript:void(0);" class="sui-btn btn-bordered btn-small btn-danger" ms-click="DelFile2(el,1)">删除</a> </label>
                    </label>
                </li>
                <li class="span2">
                    <button ms-click="FileUpload2(1)" style="margin:15px 0" class="sui-btn btn-xlarge btn-success">添加图片</button>
                </li>
            </ul>
        </div>
    </div>


    <div class="control-group" ms-if="ModelData.ID>0">
        <label class="control-label v-top">
            社区状态：
        </label>
        <div class="controls">
            <span class="sui-text-info" ms-if="ModelData.Status==0">待审核</span>
            <span class="sui-text-success" ms-if="ModelData.Status==1">审核通过</span>
            <span class="sui-text-danger" ms-if="ModelData.Status==9">审核未通过</span><br />

            <a href="javascript:void(0);" class="sui-btn btn-large btn-success" ms-if="ModelData.Status==0" ms-click="Check(1)" style="margin-left:20px;">审核通过</a>
            <a href="javascript:void(0);" class="sui-btn btn-large btn-danger" ms-if="ModelData.Status==0" ms-click="Check(9)">审核不通过</a>
        </div>
    </div>

    
</div>

<script type="text/javascript">
    var tempmodel = avalon.define({
        $id: "tmpmodelview",
        ModelData: { "Client": "", "ID": 0,"Type1":"", "Title": "", "Desp": "", "ImgUrl": "", "Contact": "", "ContactTel": "", "Address": "", "Status": "-1", "ImgUrl2": "", "Summary": "","License":"" },
        ClientList: [],
        TypeList2: [],
        FileData2: [],
        TypeData:[],
        Init: function (ID) {
            $.getJSON("/adapi/base/cate/list/2/0", function (r) {
                if (r.error == "") {
                    tempmodel.TypeData = r.result;
                }
            })
            $.getJSON("/adapi/base/client/list", function (r) {
                if (r.error == "") {
                    tempmodel.ClientList = r.result;
                }

            })

            if (ID) {
                $.getJSON("/adapi/vendor/model/" + ID, function (r) {
                    if (r.error == "") {
                        tempmodel.ModelData = r.result;
                        if (r.result.ImgUrl) {
                            pmodel.FileData = r.result.ImgUrl.split(",");
                        }
                        if (r.result.ImgUrl2) {
                            tempmodel.FileData2 = r.result.ImgUrl2.split(",");
                        }
                    }

                })
            }

        },
        tmpSaveData: function () {
            
            tempmodel.ModelData.ImgUrl = pmodel.FileData.toString();
            tempmodel.ModelData.ImgUrl2 = tempmodel.FileData2.toString();

            $.post("/adapi/vendor/add", tempmodel.ModelData.$model, function (r) {
                if (r.error == "") {
                    top.ComFunJS.winShowMsg("操作成功");
                    top.ComFunJS.close();
                } else {
                    top.ComFunJS.winShowAlert(r.error);
                }

            })
        },
        Check: function (st) {
            if (tempmodel.ModelData.ID) {

                if (st == 1) {
                    var desp = "<span style='color:red;'>确定要审核通过吗?<span>";
                } else if (st == 9) {
                    var desp = "<span style='color:red;'>确定审核不通过吗?<span>";
                }

                top.ComFunJS.winShowConfirm(desp, function () {
                    $.getJSON("/adapi/vendor/check/" + tempmodel.ModelData.ID + "/" + st, function (r) {
                        if (r.error == "") {
                            tempmodel.ModelData.Status = st;
                            top.ComFunJS.winShowMsg("操作成功");
                            top.ComFunJS.close();

                        } else {
                            top.ComFunJS.winShowAlert(r.error);
                        }

                    })
                })

            }

        },
        FileUpload2: function (s) {
            ComFunJS.fileUpload(function (result) {
                if (s == 1) {
                    result.forEach(function (item, index) {
                        tempmodel.FileData2.push(item.ID);
                    })
                } else if (s == 2) {
                    tempmodel.ModelData.License = result[0].ID;
                }
                

            })
        },
        DelFile2: function (el, s) {
            if (s == 1) {
                if (el) {
                    tempmodel.FileData2.remove(el);
                }
            } else if (s == 2) {
                tempmodel.ModelData.License = "";
            }
            
        }

    })

    tempmodel.$watch("ModelData.Client", function () {
        var cityl = {};
        tempmodel.ClientList.forEach(function (value, index) {
            if (tempmodel.ModelData.Client == value.ID) {
                cityl = value;
            }

        })

        tempmodel.ModelData.Province = cityl.Province;
        tempmodel.ModelData.City = cityl.City;

        
    })

    tempmodel.$watch("ModelData.Province", function () {
        pmodel.GetCityData2(tempmodel.ModelData.Province);
    })

    tempmodel.$watch("ModelData.City", function () {
        pmodel.GetCityData3(tempmodel.ModelData.City);
    })

    //tempmodel.$watch("ModelData.Type1", function () {
    //    tempmodel.TypeList2.clear();
    //    if (tempmodel.ModelData.Type1) {
    //        $.getJSON("/adapi/base/cate/list/1/" + tempmodel.ModelData.Type1, function (r) {
    //            tempmodel.TypeList2 = r.result;
    //        })
    //    }

    //})

</script>
